﻿using AutoMapper.Internal.Mappers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Himp.Erp
{
    /// <summary>
    /// 库存变更类别
    /// </summary>
    public class InvChgTypeService : CrudAppService<InvChgType, InvChgTypeDto, Guid, InvChgTypeInput, InvChgTypeCreateOrUpdateDto, InvChgTypeCreateOrUpdateDto>, IInvChgTypeService
    {
        private IRepository<InvChgType, Guid> _materialSupplierRepository;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="projectConfigRepository"></param>
        public InvChgTypeService(IRepository<InvChgType, Guid> materialSupplierRepository) : base(materialSupplierRepository)
        {
            _materialSupplierRepository = materialSupplierRepository;
        }

        /// <summary>
        /// 获取物料供应商信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override async Task<PagedResultDto<InvChgTypeDto>> GetListAsync(InvChgTypeInput input)
        {
            var iQuery = await _materialSupplierRepository.GetQueryableAsync();

            if (input.Pi == 0)
            {
                var itemsDto = ObjectMapper.Map<List<InvChgType>, List<InvChgTypeDto>>(iQuery.ToList());

                return new PagedResultDto<InvChgTypeDto>(itemsDto.Count, itemsDto);
            }
            else
            {
                var totalCount = iQuery.Count();
                var items = iQuery.Page(input.Pi, input.Ps);
                var itemsDto = ObjectMapper.Map<List<InvChgType>, List<InvChgTypeDto>>(items.ToList());

                return new PagedResultDto<InvChgTypeDto>(totalCount, itemsDto);
            }
        }
    }
}
